package org.jbelis.yodaquotes;

import java.io.Writer;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import org.json.JSONException;
import org.json.JSONWriter;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Quote {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Long id;

    @Persistent
    private String text;

    @Persistent
    private String author;

    @Persistent
    private String context;

    public Quote(String text, String author, String context) {
        this.text = text;
        this.author = author;
        this.context = context;
    }

	public Long getId() {
        return id;
    }

    public String getText() {
        return text;
    } 

    public String getContext() {
        return context;
    } 

    public String getAuthor() {
        return author;
    } 
    
    public void write(Writer writer) throws JSONException {
		JSONWriter json = new JSONWriter(writer);

		json.object();
		json.key("text");
		json.value(getText());
		json.key("author");
		json.value(getAuthor());
		json.endObject();

    }

}

